﻿//Copyright Notice:  ©2009 Microsoft Corporation.  All rights reserved.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace Microsoft.InformationSecurity.CISF.Security.AuthZServices
{
    /// <summary>
    /// Contains the property value(s) for a single property type for a directory entry.
    /// </summary>
    public abstract class Property : Collection<string>
    {
        #region Private Variables
        internal AuthZGlobals.PropertyType type;

        #endregion

        #region Constructor
        /// <summary>
        /// Contains the property value(s) for a single property type for a directory entry.
        /// </summary>
        public Property()
        {
        }

        /// <summary>
        /// Contains the property value(s) for a single property type for a directory entry.
        /// </summary>
        /// <param name="type">Type of Property object to add value to.</param>
        public Property(AuthZGlobals.PropertyType type)
        {
            this.type = type;
        }

        /// <summary>
        /// Contains the property value(s) for a single property type for a directory entry.
        /// </summary>
        /// <param name="type">Type of Property object to add value to.</param>
        /// <param name="value">A value to be added to the value collection for this Property.</param>
        public Property(AuthZGlobals.PropertyType type, string value)
        {
            this.type = type;
            this.Add(value);
        }

        #endregion

        #region Methods

        #region Add
        /// <summary>
        /// Adds the provided value to this Propery object.
        /// </summary>
        /// <param name="value">A value to be added to the value collection for this Property.</param>
        /// <param name="noDuplicates">true - A value cannot be added as a duplicate value
        /// in the Property object.</param>
        public void Add(string value, bool noDuplicates)
        {
            if (!this.Contains(value) || !noDuplicates)
                this.Add(value);
        }

        /// <summary>
        /// Adds the provided value to this Propery object.
        /// </summary>
        /// <param name="property">A value to be added to the value collection for this Property.</param>
        /// <param name="noDuplicates">true - A value cannot be added as a duplicate value
        /// in the Property object.</param>
        public void Add(Property property, bool noDuplicates)
        {
            foreach (string value in property)
                this.Add(value, noDuplicates);
        }

        #endregion

        #endregion

        #region Properties

        #region Type
        /// <summary>
        /// Gets the property type.
        /// </summary>
        public AuthZGlobals.PropertyType Type
        {
            get { return type; }
        }

        #endregion

        #endregion

    }
}
